var a = getApp();

Page({
    data: {
        SearchValue: "",
        Height: 0,
        LastHeight: 0,
        language: "",
        list: [],
        last_page: 0,
        current_page: 0,
        banner: "",
        mini_url: "",
        machineId: ""
    },
    onLoad: function(t) {
        if (t.scene) {
            var e = decodeURIComponent(t.scene);
            if (e) {
                var i = [];
                i = e.split(",");
                for (var n = 0; n < i.length; n++) {
                    var s;
                    s = i[n].split("="), console.log(s), "machine_id" == s[0] ? this.setData({
                        machineId: s[1]
                    }) : "mid" == s[0] && a._setMid(s[1]);
                }
            }
        } else (t.id || t.machine_id) && this.setData({
            machineId: t.id || t.machine_id
        });
        this.getBanner(), this.getData(), this.imgHeight();
        var d = wx.getStorageSync("langIndex");
        this.setData({
            language: d.en
        });
    },
    link: function() {
        wx.navigateTo({
            url: this.data.mini_url
        });
    },
    getBanner: function() {
        var t = this;
        a._getNetWork({
            url: a.getNetAddresss("plugin.automat.frontend.index.index"),
            data: {
                automat_machine_id: this.data.machineId
            },
            success: function(e) {
                var i = e.data, n = i.result, s = i.msg, d = i.data;
                n ? (t.setData({
                    mini_url: d.mini_route,
                    banner: d.banner,
                    machineId: d.id
                }), wx.setNavigationBarTitle({
                    title: d.name
                })) : a.tips(s);
            }
        });
    },
    toSearch: function() {
        wx.navigateTo({
            url: "/packageB/member/category/search_v2/search_v2?machineId=" + this.data.machineId
        });
    },
    link_order: function() {
        wx.navigateTo({
            url: "/packageA/member/myOrder_v2/myOrder_v2?status=0"
        });
    },
    buy: function(a) {
        wx.navigateTo({
            url: "/packageA/detail_v2/detail_v2?id=" + a.currentTarget.dataset.id + "&machineId=" + this.data.machineId
        });
    },
    imgHeight: function(a) {
        var t = wx.getSystemInfoSync().windowWidth;
        if (a && a.detail) {
            var e = t * a.detail.height / a.detail.width;
            parseInt(e) > this.data.LastHeight && (this.setData({
                Height: e
            }), this.data.LastHeight = parseInt(e));
        }
    },
    getData: function(t) {
        var e = this, i = t || 1, n = {
            automat_machine_id: this.data.machineId,
            "search[automat_machine_id]": this.data.machineId,
            page: i
        };
        a._getNetWork({
            url: a.getNetAddresss("plugin.automat.frontend.goods.searchGoods"),
            data: n,
            success: function(t) {
                var n = t.data, s = n.result, d = n.msg, r = n.data;
                s ? (e.setData({
                    last_page: r.last_page,
                    current_page: r.current_page
                }), 1 == i ? e.setData({
                    list: r.data
                }) : e.setData({
                    list: e.data.list.concat(r.data)
                })) : a.tips(d);
            }
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        if (!(this.data.current_page >= this.data.last_page)) {
            var a = this.data.current_page + 1;
            this.getData({
                page: a
            });
        }
    },
    onShareAppMessage: function() {}
});